package com.i8office.android.zhihuixinwu.module.model;

import com.cyan.tools.callback.RequestCallback;
import com.i8office.android.zhihuixinwu.app.App;
import com.i8office.android.zhihuixinwu.bean.Code;
import com.i8office.android.zhihuixinwu.bean.Result;
import com.i8office.android.zhihuixinwu.module.contract.CalendarContract;
import com.i8office.android.zhihuixinwu.ui.schedule.CheckInGroup;
import com.i8office.android.zhihuixinwu.ui.schedule.DayItem;
import com.i8office.android.zhihuixinwu.ui.schedule.EventItem;
import com.i8office.android.zhihuixinwu.ui.schedule.LeaderData;
import com.i8office.android.zhihuixinwu.ui.schedule.Meetting;
import com.i8office.android.zhihuixinwu.ui.schedule.ScheduleData;
import com.i8office.android.zhihuixinwu.util.OfficeSubscriber;

import java.util.List;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class CalendarModel implements CalendarContract.Model {
    @Override
    public Disposable getCalendarData(RequestCallback<List<DayItem>> callback, Map<String, String> params) {
        return App.getComponent().getAPIService().getCalendarData(params)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new OfficeSubscriber<Result<List<DayItem>>>(callback));
    }

    @Override
    public Disposable getEventsByDate(RequestCallback<List<EventItem>> callback, Map<String, String> params) {
        return App.getComponent().getAPIService().getEventsByDate(params)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new OfficeSubscriber<Result<List<EventItem>>>(callback));
    }

    @Override
    public Disposable getScheduleList(RequestCallback<List<EventItem>> callback, Map<String, String> params) {
        return App.getComponent().getAPIService().getScheduleList(params)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new OfficeSubscriber<Result<List<EventItem>>>(callback));
    }

    @Override
    public Disposable getLeaderScheduleByName(RequestCallback<ScheduleData> callback, Map<String, String> params) {
        return App.getComponent().getAPIService().getLeaderScheduleByName(params)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new OfficeSubscriber<ScheduleData>(callback));
    }
    @Override
    public Disposable getLeaderScheduleByDate(RequestCallback<ScheduleData> callback, Map<String, String> params) {
        return App.getComponent().getAPIService().getLeaderScheduleByDate(params)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new OfficeSubscriber<ScheduleData>(callback));
    }

    @Override
    public Disposable removeEvent(RequestCallback<Code> callback, Map<String, String> params) {
        return App.getComponent().getAPIService().deleteEvent(params)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new OfficeSubscriber<Code>(callback));
    }

    @Override
    public Disposable addEvent(RequestCallback<Code> callback, Map<String, String> params) {
        return App.getComponent().getAPIService().addEvent(params)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new OfficeSubscriber<Code>(callback));
    }

    @Override
    public Disposable updateEvent(RequestCallback<Code> callback, Map<String, String> params) {
        return App.getComponent().getAPIService().updateEvent(params)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new OfficeSubscriber<Code>(callback));
    }

    @Override
    public Disposable updateOtherEvent(RequestCallback<Code> callback, Map<String, String> params) {
        return App.getComponent().getAPIService().updateOtherEvent(params)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new OfficeSubscriber<Code>(callback));
    }

    @Override
    public Disposable getLeadersData(RequestCallback<LeaderData> callback) {
        return App.getComponent().getAPIService().getLeadersData()
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new OfficeSubscriber<Result<LeaderData>>(callback));
    }
    @Override
    public Disposable getGroupLeadersData(RequestCallback<LeaderData> callback) {
        return App.getComponent().getAPIService().getGroupLeadersData()
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new OfficeSubscriber<Result<LeaderData>>(callback));
    }

    @Override
    public Disposable getMeettings(RequestCallback<List<Meetting>> callback, Map<String, String> params) {
        return App.getComponent().getAPIService().getMeettings(params)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new OfficeSubscriber<Result<List<Meetting>>>(callback));
    }

    @Override
    public Disposable checkInGroup(RequestCallback<CheckInGroup> callback) {
        return App.getComponent().getAPIService().checkInGroup()
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new OfficeSubscriber<CheckInGroup>(callback));
    }
}
